home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2998 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.3 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: class declaration question
  5. Date: Sun, 21 Jan 1996 12:31:27 GMT
  6. Organization: Netcom
  7. Message-ID: <3102311d.216834688@nntp.ix.netcom.com>
  8. References: <4dphp6$1bp@noc2.drexel.edu> <Robert.Lendvai-2101960127070001@129.170.80.94>
  9. NNTP-Posting-Host: ix-dc10-02.ix.netcom.com
  10. X-NETCOM-Date: Sun Jan 21  4:31:14 AM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. Robert.Lendvai@dartmouth.edu (Robert Lendvai) wrote:
  14.  
  15. > In article <4dphp6$1bp@noc2.drexel.edu>, st918h5w@dunx1.ocs.drexel.edu
  16. > (Jonathan Juniman) wrote:
  17. > > Is it necessary to do this:
  18. > > 
  19. > > class SomeClass
  20. > >         {
  21. > >         public:
  22. > >         void Somefunction(int SomeParameter);
  23. > >         }
  24. > > 
  25. > > or is it just as legal to do this:
  26. > > class SomeClass
  27. > >         {
  28. > >         public:
  29. > >         void SomeFunction(int);
  30. > >         }
  31. > > 
  32. > > The latter seems to be the convention, but why does the compiler need to
  33. > > know the name of SomeFunction's argument?  Isn't it sufficient to know the
  34. > > type of Somefunction's argument (namely, int)?  
  35. > > 
  36. > > Please reply by e-mail.  PS; thanks to all the people who answered my
  37. > > overloaded operator question.
  38. > > 
  39. > >                                         Jon
  40. > John,
  41. >    i think you need to go with the former (int SomeParameter). I'm not
  42. > sure if the other way is legal, but even so, you need to know the name of
  43. > the argument so that you may manipulate it in the function definition.
  44. > Otherwise, how would you refer to the argument's value.
  45.  
  46. You don't refer to the argument's value.  This is a declaration of the
  47. member function, not a definition.  There is no body in which to refer
  48. to the argument's value.
  49.  
  50. In a (member) function definition, you must supply the parameter name
  51. if you want to use it in the function body.  Occasionally you have a
  52. function with a parameter that is not used and in that case it is not
  53. necessary to give it a name.
  54.  
  55. The name may be omitted in a declaration and supplied in the
  56. definition for the same function.  Or it may be different in the two.
  57.  
  58. Either of the above is legal and choice is really a matter of style.
  59. Some compilers will give better error messages if a meaningful name is
  60. given to the parameter so I prefer to do so.
  61.  
  62.  
  63. Michael M Rubenstein
  64.